home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / svgacc25.zip / SVGADEMO.C < prev    next >
Text File  |  1997-03-24  |  18KB  |  615 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft compatible
  4.       C/C++ compilers
  5.       Copyright 1993-1997 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  8.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  9.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  10.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  11.     **********************************************************************
  12.  
  13.     **************** NO WARRANTIES AND NO LIABILITY **********************
  14.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  15.     * expressed or implied, of merchantability, or fitness, for a        *
  16.     * particular use or purpose of this SOFTWARE and documentation.      *
  17.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  18.     * liable for any damages resulting from the use or misuse of the     * 
  19.     * SOFTWARE and documentation.                                        *
  20.     **********************************************************************
  21.  
  22.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  23.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  24.     * by the U.S. Government is subject to the restictions as set forth  *
  25.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  26.     * Computer Software cluse at DFARS 252.227-7013.                     *
  27.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  28.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  29.     **********************************************************************
  30.  
  31.     **********************************************************************
  32.     * By using this SOFTWARE or documentation, you agree to the above    *
  33.     * terms and conditions.                                              *
  34.     **********************************************************************
  35.  
  36.  ***************************************************************************/
  37.     
  38.  
  39. #include <stdio.h>
  40. #include <conio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <math.h>
  44. #include <dos.h>
  45.  
  46. #include "svgacc.h"
  47.  
  48. #include "svgademo.h"
  49.  
  50.  
  51. void main(void) {
  52.  
  53.     int startvideomode;
  54.     int i, max, ky;
  55.     int mjv, mnv, tp;
  56.     int cpu, videomemory;
  57.     int mouse, joystick;
  58.     int res;
  59.     int offset, colr;
  60.     float mypi;
  61.     char dummy;
  62.     char buf[TITLEN];
  63.     char *dumptr;
  64.     
  65.     
  66.     /*
  67.      * Save the starting videomode and set it to mode 3.
  68.      */
  69.     startvideomode = videomodeget();
  70.     restext();
  71.     screenclear();
  72.     
  73.     /*
  74.      * Move the DOS cursor to the top left to start the program and say hello
  75.      */
  76.     screengoto(11,0);
  77.     printf("/*SVGACC.LIB/* A SuperVGA Graphics Library for use with\n");
  78.     screengoto(23,1);
  79.     printf("Microsoft compatible C/C++ compilers\n");
  80.     screengoto(9,2);
  81.     printf("Copyright 1993-1997 by Stephen L. Balkum and Daniel A. Sill\n");
  82.     screengoto(23,11);
  83.     printf("Demonstration/Example Program\n");
  84.     screengoto(0,22);
  85.     printf("press a key to begin the demo...\n");
  86.     getkey();
  87.  
  88.     screenclear();
  89.    
  90.     /*
  91.      * Let's id the processor first as the library requires a 386 or better.
  92.      */
  93.     screengoto(0,0);
  94.     cpu = whichcpu();
  95.     if (cpu < 386) {
  96.         printf("Sorry, this library requires an 80386 or better processor.\n");
  97.         printf("Processor is identified as an 80%d.\n", cpu);
  98.         printf("Demo program will be terminated.\n\n");
  99.         printf("press a key...\n");
  100.         getkey();
  101.         videomodeset(startvideomode);
  102.         exit(0);
  103.     }
  104.  
  105.  
  106.     /*
  107.      * Let's id the video card/chip as the library requires a SuperVGA adapter.
  108.      */
  109.     switch(whichvga()) {
  110.         case ACUMOS:
  111.             sprintf(buf,"Acumos AVGA2/3 SuperVGA");
  112.             break;
  113.         case ATI:
  114.             sprintf(buf,"ATI Technologies 18/28/38/68800 SuperVGA");
  115.             break;
  116.         case AHEADA:
  117.             sprintf(buf,"Ahead V5000 Ver A SuperVGA");
  118.             break;
  119.         case AHEADB:
  120.             sprintf(buf,"Ahead V5000 Ver B SuperVGA");
  121.             break;
  122.         case CHIPSTECH:
  123.             sprintf(buf,"Chips and Technologies 82C450/1/2/3/5/6/7 SuperVGA");
  124.             break;
  125.         case CIRRUS:
  126.             sprintf(buf,"Cirrus Logic CL-GD 5xx,6xx,28xx,54xx,62xx SuperVGA");
  127.             break;
  128.         case EVEREX:
  129.             sprintf(buf,"Everex EV236/6xx Micro Enhancer SuperVGA");
  130.             break;
  131.         case GENOA:
  132.             sprintf(buf,"Genoa 61/62/63/64/6600 SuperVGA");
  133.             break;
  134.         case NCR:
  135.             sprintf(buf,"NCR 77C21/22/22E/22E+ SuperVGA");
  136.             break;
  137.         case OAKTECH:
  138.             sprintf(buf,"Oak Technologies OTI-037/67/77/87C SuperVGA");
  139.             break;
  140.         case PARADISE:
  141.             sprintf(buf,"Paradise/Western Digital PVGA1A,WD90C00/1x/2x/3x SuperVGA");
  142.             break;
  143.         case REALTEK:
  144.             sprintf(buf,"Realtek RT3106 SuperVGA");
  145.             break;
  146.         case TRIDENT:
  147.             sprintf(buf,"Trident 8800CS,8900B/C/CL/CX,90x0 SuperVGA");
  148.             break;
  149.         case TSENG3:
  150.             sprintf(buf,"Tseng Labs ET3000-AX/BX/BP SuperVGA");
  151.             break;
  152.         case TSENG4:
  153.             sprintf(buf,"Tseng Labs ET4000/W32/W32I SuperVGA");
  154.             break;
  155.         case VESA:
  156.             sprintf(buf,"VESA compatible SuperVGA");
  157.             break;
  158.         case VIDEO7:
  159.             sprintf(buf,"Video 7 HT-208/16 SuperVGA");
  160.             break;
  161.         case AVANCE:
  162.             sprintf(buf,"Avance Logic AL2101 SuperVGA");
  163.             break;
  164.         case MXIC:
  165.             sprintf(buf,"MXIC MX68000/10 SuperVGA");
  166.             break;
  167.         case PRIMUS:
  168.             sprintf(buf,"Primus P2000 SuperVGA");
  169.             break;
  170.         default:
  171.             printf("Microprocessor is identified as an 80%d.\n", cpu);
  172.             printf("Sorry, unable to identify video card or it is not a SuperVGA video adapter.\n");
  173.             printf("Demo program will be terminated.\n\n");
  174.             printf("press a key...\n");
  175.             getkey();
  176.             videomodeset(startvideomode);
  177.             exit(0);
  178.     }
  179.     printf("Microprocessor is identified as an 80%d.\n", cpu);
  180.     
  181.     fontsystem();
  182.     printf("Video card/chip is identified as %s.\n",&buf);
  183.    
  184.     /*
  185.      * Let's see the how much memory is installed on the super vga adapter.
  186.      */
  187.     videomemory = whichmem();
  188.     if (videomemory < 1) {
  189.         printf("Sorry, unable to identify the amount of installed video memory.\n");
  190.         printf("Demo program will be terminated.\n\n");
  191.         printf("press a key...\n");
  192.         getkey();
  193.         videomodeset(startvideomode);
  194.         exit(0);
  195.     } else
  196.         printf("Installed video memory identified as %dkb.\n", videomemory);
  197.        
  198.     /*
  199.      * Let's tell the user what the highest resolution that the video card
  200.      * and its installed memory card is capable of. The monitor must be able
  201.      * to support those modes too !
  202.      */
  203.     printf("Video card and installed memory is capable of the following resolutions:\n");
  204.     if (videomemory > 2047) {
  205.         printf("    320x200 in 256 colors\n");
  206.         printf("    640x400 in 256 colors\n");
  207.         printf("    640x480 in 256 colors\n");
  208.         printf("    800x600 in 256 colors\n");
  209.         printf("    1024x768 in 256 colors\n");
  210.         printf("    1280x1024 in 256 colors\n");
  211.         max = 5;
  212.     } else if (videomemory > 1023) {
  213.         printf("    320x200 in 256 colors\n");
  214.         printf("    640x400 in 256 colors\n");
  215.         printf("    640x480 in 256 colors\n");
  216.         printf("    800x600 in 256 colors\n");
  217.         printf("    1024x768 in 256 colors\n");
  218.         max = 4;
  219.     } else if (videomemory > 511) {
  220.         printf("    320x200 in 256 colors\n");
  221.         printf("    640x400 in 256 colors\n");
  222.         printf("    640x480 in 256 colors\n");
  223.         printf("    800x600 in 256 colors\n");
  224.         max = 3;
  225.     } else {
  226.         printf("    320x200 in 256 colors\n");
  227.         printf("    640x400 in 256 colors\n");
  228.         max = 1;
  229.     }
  230.     printf("\nPlease keep in mind that not all monitors support all resolutions. If You\n");
  231.     printf("know your monitor will not work properly at very high resolution(ie 1024x768\n");
  232.     printf("or 1280x1024) then do NOT attempt to run the demo in that resolution.\n\n");
  233.  
  234.     /*
  235.      * Let's look for a mouse. if we find one, tell all about it
  236.      */
  237.     mouse = whichmouse();
  238.     if (mouse > 0) {
  239.         mouseinfo(&mjv, &mnv, &tp, &i);
  240.         switch (tp) {
  241.             case 1:
  242.                 sprintf(buf,"bus mouse");
  243.                 break;
  244.             case 2:
  245.                 sprintf(buf,"serial mouse");
  246.                 break;
  247.             case 3:
  248.                 sprintf(buf,"Inport mouse");
  249.                 break;
  250.             case 4:
  251.                 sprintf(buf,"PS/2 mouuse");
  252.                 break;
  253.             case 5:
  254.                 sprintf(buf,"HP mouse");
  255.                 break;
  256.             default:
  257.                 sprintf(buf,"unknown type");
  258.         }
  259.         printf("Microsoft compatible %s detected with %d buttons on IRQ %d.\n", &buf, mouse, i);
  260.         printf("Software driver version is %d.%d (Microsoft equivalent version).\n\n", mjv, mnv);
  261.  
  262.     } else
  263.         printf("No Microsoft compatible mouse detected.\n\n");
  264.  
  265.     /*
  266.      * Let's look for joysticks
  267.      */
  268.     joystick = whichjoystick();
  269.     switch (joystick) {
  270.         case -1:
  271.             printf("No joystick port detected or no joystick BIOS support present.\n\n");
  272.             break;
  273.         case 0:
  274.             printf("No joystick detected\n\n");
  275.             break;
  276.         case 1:
  277.             printf("Joystick A is present and available.\n\n");
  278.             break;
  279.         case 2:
  280.             printf("Joystick B is present and available.\n\n");
  281.             break;
  282.         case 3:
  283.             printf("Both Joystick A and Joystick B are present and available.\n\n");
  284.             break;
  285.     }
  286.     printf("press a key...\n");
  287.     getkey();
  288.  
  289.  
  290.     /*
  291.      * Let's get down to business
  292.      */
  293.     res = 1;
  294.     endit = 0;
  295.     ky=0;
  296.     
  297.     /*
  298.      * Init alternate color palettes
  299.      */
  300.  
  301.     res320();
  302.     palget(orgpal, 0, 255);
  303.     palcopy(orgpal,pal,0,255);
  304.     palcopy(orgpal,pal2,0,255);
  305.     mypi=(float)(8 * atan(1) / 240);
  306.     offset = 16;
  307.     for (colr=0;colr<240;colr++,offset++) {
  308.         pal[offset].r = (char)(32.0 + sin((colr + 0) * mypi) * 31.0);
  309.         pal[offset].g = (char)(32.0 + sin((colr + 80) * mypi) * 31.0);
  310.         pal[offset].b = (char)(32.0 + sin((colr + 160) * mypi) * 31.0);
  311.         pal2[offset].r = (char)(32.0 + sin((colr + 10) * mypi) * 31.0);
  312.         pal2[offset].g = (char)(32.0 + sin((colr + 30) * mypi) * 31.0);
  313.         pal2[offset].b = (char)(32.0 + sin((colr + 50) * mypi) * 31.0);
  314.     }
  315.     restext();
  316.  
  317.     /*
  318.      * Here is the main selector loop
  319.      */
  320.     while (endit == 0) {
  321.         screenclear();
  322.         switch (res) {
  323.             case 1: 
  324.                 sprintf(buf,"320x200x256");
  325.                 break;
  326.             case 2:
  327.                 sprintf(buf,"640x400x256");
  328.                 break;
  329.             case 3:
  330.                 sprintf(buf,"640x480x256");
  331.                 break;
  332.             case 4:
  333.                 sprintf(buf,"800x600x256");
  334.                 break;
  335.             case 5:
  336.                 sprintf(buf,"1024x768x256");
  337.                 break;
  338.             case 6:
  339.                 sprintf(buf,"1280x1024x256");
  340.         }
  341.         printf("Please select the demo you would like to see in the %s resolution:\n\n",&buf);
  342.         printf("(0)  Exit This Program\n\n");
  343.         printf("(1)  Demo #1  The Primitive Drawing Routines\n");
  344.         printf("(2)  Demo #2  The Clipping Capabilities\n");
  345.         printf("(3)  Demo #3  The Fill Routines\n");
  346.         printf("(4)  Demo #4  The Palette Routines\n");
  347.         printf("(5)  Demo #5  The Block Routines\n");
  348.         printf("(6)  Demo #6  The Text Routines\n");
  349.         printf("(7)  Demo #7  The Scrolling and Paging Routines\n");
  350.         printf("(8)  Demo #8  The PCX Routines\n");
  351.         printf("(9)  Demo #9  The Mouse Routines\n");
  352.         printf("(10) Demo #10 The Joystick Routines\n");
  353.         printf("(11) Demo #11 The Two Dimensional Routines\n");
  354.         printf("(12) Demo #12 The Three Dimensional Routines\n");
  355.         printf("(13) The Grand Tour of All Demos\n");
  356.         printf("(14) Use 320x200 in 256 colors\n");
  357.         printf("(15) Use 640x400 in 256 colors\n");
  358.         max = 15;
  359.         if (videomemory > 511) {
  360.             printf("(16) Use 640x480 in 256 colors\n");
  361.             printf("(17) Use 800x600 in 256 colors\n");
  362.             max = 17;
  363.         } 
  364.         if (videomemory > 1023) {
  365.             printf("(18) Use 1024x768 in 256 colors\n");
  366.             max = 18;
  367.         }
  368.         if (videomemory > 2047) {
  369.             printf("(19) Use 1280x1024 in 256 colors\n");
  370.             max = 19;
  371.         }
  372.  
  373.         printf("\nYour Choice: ");
  374.         for (i=0;i<3;i++) {
  375.             dummy = (char)getch();
  376.             switch (dummy) {
  377.                 case 13:
  378.                     if (i == 0)
  379.                         i--;
  380.                     else {
  381.                         buf[i]='\0';
  382.                         i=2;
  383.                     }
  384.                     break;
  385.                 case 8:
  386.                     i--;
  387.                     if (i > (-1)) {
  388.                         printf("\b \b");
  389.                         i--;
  390.                     }
  391.                     break;
  392.                 default:
  393.                     if ((dummy < '0') || (dummy > '9'))
  394.                         i--;
  395.                     else if (i < 2) {
  396.                         printf("%c",dummy);
  397.                         buf[i] = dummy;
  398.                     } else
  399.                         buf[i] = '\0';
  400.  
  401.             }
  402.         }
  403.         ky=(int)strtol(buf,&dumptr,10);
  404.  
  405.         if (ky > max)
  406.             ky = 99;
  407.     
  408.         if((ky > 0) && (ky < 14))
  409.             switch (res) {
  410.                 case 1:
  411.                     res320();
  412.                     break;
  413.                 case 2:
  414.                     res640l();
  415.                     break;
  416.                 case 3:
  417.                     res640();
  418.                     break;
  419.                 case 4:
  420.                     res800();
  421.                     break;
  422.                 case 5:
  423.                     res1024();
  424.                     break;
  425.                 case 6:
  426.                     res1280();
  427.                     break;
  428.             }
  429.         
  430.         switch (ky) {
  431.             case 0:
  432.                 endit = 1;
  433.                 break;
  434.             case 1:
  435.                 doprims();
  436.                 break;
  437.             case 2:
  438.                 doclip();
  439.                 break;
  440.             case 3:
  441.                 dofill();
  442.                 break;
  443.             case 4:
  444.                 dopal();
  445.                 break;
  446.             case 5:
  447.                 doblock();
  448.                 break;
  449.             case 6:
  450.                 dotext();
  451.                 break;
  452.             case 7:
  453.                 doscroll();
  454.                 break;
  455.             case 8:
  456.                 dopcx();
  457.                 break;
  458.             case 9:
  459.                 domouse();
  460.                 break;
  461.             case 10:
  462.                 dojoystick();
  463.                 break;
  464.             case 11:
  465.                 do2d();
  466.                 break;
  467.             case 12:
  468.                 do3d();
  469.                 break;
  470.             case 13:
  471.                 doall();
  472.                 break;
  473.             case 14:
  474.                 res = 1;
  475.                 break;
  476.             case 15:
  477.                 res = 2;
  478.                 break;
  479.             case 16:
  480.                 res = 3;
  481.                 break;
  482.             case 17:
  483.                 res = 4;
  484.                 break;
  485.             case 18:
  486.                 res = 5;
  487.                 break;
  488.             case 19:
  489.                 res = 6;
  490.                 break;
  491.  
  492.             default:
  493.                 ;
  494.  
  495.         }
  496.         
  497.         restext();
  498.         
  499.     }
  500.  
  501.     videomodeset(startvideomode);
  502.  
  503. }
  504.  
  505. /**********               
  506.  * GETKEY *
  507.  **********/
  508.  
  509. char getkey(void)
  510. {
  511.     char ret;
  512.     beep();
  513.     ret = (char)getch();
  514.     if ( (ret == 'Q') || (ret == 'q') )
  515.         endit = 1;
  516.     if (ret == 'Q')
  517.         ret = 'q';
  518.     if (ret == 'S')
  519.         ret = 's';
  520.     
  521.     return(ret);
  522. }
  523.  
  524.  
  525. /*********
  526.  * DOALL *
  527.  *********/
  528.  
  529. void doall(void)
  530. {
  531.     if(doprims()=='q')
  532.         return;
  533.     if(doclip()=='q')
  534.         return;
  535.     if(dofill()=='q')
  536.         return;
  537.     if(dopal()=='q')
  538.         return;
  539.     if(doblock()=='q')
  540.         return;
  541.     if(dotext()=='q')
  542.         return;
  543.     if(doscroll()=='q')
  544.         return;
  545.     if(dopcx()=='q')
  546.         return;
  547.     if(domouse()=='q')
  548.         return;
  549.     if(dojoystick()=='q')
  550.         return;
  551.     if(do2d()=='q')
  552.         return;
  553.     if(do3d()=='q')
  554.         return;
  555.  
  556.     return;
  557.  
  558. }
  559.  
  560.  
  561. /***************
  562.  * SCREENCLEAR *
  563.  ***************/
  564.  
  565. void screenclear(void)
  566. {
  567.     union REGS regs;
  568.  
  569.     regs.h.ah = 0x07;
  570.     regs.h.al = 0x00;
  571.     regs.h.ch = 0;
  572.     regs.h.cl = 0;
  573.     regs.h.dh = 24;
  574.     regs.h.dl = 79;
  575.     regs.h.bh = 7;
  576.     int86(0x10, ®s, ®s);
  577.     screengoto(1,1);
  578. }
  579.  
  580.  
  581. /**************
  582.  * SCREENGOTO *
  583.  **************/
  584.  
  585. void screengoto(int x, int y)
  586. {
  587.     union REGS regs;
  588.  
  589.     regs.h.ah = 0x02;
  590.     regs.h.bh = 0;
  591.     regs.h.dh = (unsigned char)y;
  592.     regs.h.dl = (unsigned char)x;
  593.     int86(0x10, ®s, ®s);
  594. }
  595.  
  596. /********
  597.  * BEEP *
  598.  ********/
  599.  
  600. void beep(void)
  601. {
  602.  
  603.     int cont;
  604.  
  605.     outp(0x43,0xB6);
  606.     outp(0x42,0xA9);
  607.     outp(0x42,0x06);
  608.     cont = inp(0x61);
  609.     outp(0x61,cont | 0x03);
  610.     sdelay(4);
  611.     outp(0x61,cont);
  612.  
  613. }
  614.